<?php


namespace app\api\controller\v1;


use app\api\model\Banner as BannerModel;
use app\api\validate\IDMustBePositiveInt;
use app\BaseController;
use app\lib\exception\BannerMissException;

class Banner extends BaseController
{
    public function getBanner($id)
    {

//        $check = new IDMustBePositiveInt();
//        $check->goCheck();
//        throw new Exception('花木成畦手自栽');
        (new IDMustBePositiveInt())->goCheck();
//        $bannerByID = BannerModel::with(['items','items.img'])->find($id);
        $bannerByID = BannerModel::getBannerByID($id);
        if ($bannerByID->isEmpty()) {
            throw new BannerMissException();
        }
        return json($bannerByID);

    }
}